﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Pharmacy.Entities;
using Pharmacy.Data;
using Telerik.Web.UI;

public partial class Admin_ReportDrugs : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DateTime fromdate = DateTime.Now.AddMonths(-1);
            txttodate.Text = DateTime.Now.ToString("dd-MMM-yyyy");
            txtfromdate.Text = fromdate.ToString("dd-MMM-yyyy");
        }
    }
    protected void btnview_Click(object sender, EventArgs e)
    {
        string groupid = dataGroupId.SelectedValue.ToString();
        //Response.Redirect("PreviewDrugs.aspx?ID=" + groupid + "&From=" + txtfromdate.Text + "&To=" + txttodate.Text);
        string drugID = cbo_DrugID.SelectedValue.ToString();
        if (drugID == string.Empty)
        {
            Response.Redirect("PreviewDrugs.aspx?ID=" + groupid + "&From=" + txtfromdate.Text + "&To=" + txttodate.Text);

        }
        else
            Response.Redirect("PreviewDrugDetail.aspx?ID=" + groupid + "&Drugid=" + drugID + "&From=" + txtfromdate.Text + "&To=" + txttodate.Text);

            
           // Response.Redirect("PreviewDrugs.aspx?ID=" + groupid + "&From=" + txtfromdate.Text + "&To=" + txttodate.Text);


    }
    protected void cbo_DrugID_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
    {
        string groupid = dataGroupId.SelectedValue.ToString() == string.Empty ? "0" : dataGroupId.SelectedValue.ToString();
        string whereClause = String.Format("GroupId = " + groupid + " and  DrugName LIKE '{0}%'", e.Text.Replace("'", "''"));
        int count;
        TList<DrugDispo> drugDispos = DataRepository.DrugDispoProvider.GetPaged(whereClause, "DrugId", 0, 10, out count);
        foreach (DrugDispo drugDispo in drugDispos)
        {
            RadComboBoxItem item = new RadComboBoxItem();
            item.Text = drugDispo.DrugName;
            item.Value = drugDispo.DrugId;
            item.Attributes.Add("DrugId", drugDispo.DrugId);

            cbo_DrugID.Items.Add(item);
            item.DataBind();
        }
    }
}
